﻿////////////技术支持QQ：3196282049、采集修复 前端UI 二次开发 香港国内服务器租用 域名出售企业网站 个人网站ssc站  均可接单
exports.cp=[
////////////-----------------------北京PK10
  {
		title:'北京PK10',
		source:'北京PK10平台',
		name:'bjpk10',
		enable:true,
		timer:'bjpk10',

		option:{

			host:"www.bwlc.gov.cn",
			timeout:50000,
			path: '/bulletin/trax.html',
			headers:{
				"User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)"
			}
		},
		
		parse:function(str){
			try{
				return getFromPK10(str,50);
			}catch(err){
				throw('北京PK10解析数据不正确');
			}
		}
	},
	
//////////////-----------------------重庆时时彩	
  {
		title:'重庆时时彩',
		source:'360彩票网',
		name:'cqssc',
		enable:true,
		timer:'cqssc', 

		option:{
			host:"cp.360.cn",
			timeout:50000,
			path: '/ssccq/',
			headers:{
				"User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)"
			}
		},
		parse:function(str){
			try{
				return getFrom360CP(str,1);
			}catch(err){
				throw('重庆时时彩解析数据不正确');
			}
		}
	},

////////////-----------------------极速赛车
  {
        title:'极速赛车',
        source:'BOT',
        name:'jspk10',
        enable:true,
        timer:'jspk10',

        option:{

            host:"a.b1122.cc",			
            timeout:5000,
            path: '/index.php?s=/Home/Index/getJspk10Xml',
            headers:{
                "User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)"
            }
        },

        parse:function(str){
            try{                                                                                              	
                str=str.substr(0,200);	                                                                      	
                var reg=/<row expect="([\d\-]+?)" opencode="([\d\,]+?)" opentime="([\d\:\- ]+?)"/;                	
                var m;                                                                                        	
                if(m=str.match(reg)){                                                                         	
                    return {                                                                                  	
                        type:72,                                                                              	
                        time:m[3],                                                                            	
                        number:m[1],                                                                          	
                        data:m[2]                                                                             	
                    };                                                                                        	
                }					                                                                          	
            }catch(err){                                                                                      	
                throw('极速赛车 解析数据不正确');                                                            	
            }
        }
    },

////////////-----------------------重庆幸运农场
  {
		title:'重庆幸运农场',
		source:'彩乐乐网',
		name:'klsf',
		enable:true,
		timer:'klsf',

		option:{
			host:"www.cailele.com",
			timeout:50000,
			path: '/static/cqklsf/newlyopenlist.xml',
			headers:{
				"User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0)"
			}
		},		
		parse:function(str){
			try{
				//return getFromCaileWeb(str,21);
				str=str.substr(0,200);
				var reg=/<row expect="(\d+?)" opencode="([\d\,]+?)" opentime="([\d\:\- ]+?)"/; 
				//<row expect="2013072213" opencode="07,16,03,17,01,05,13,12" opentime="2013-07-22 02:03:20" />
				var m;
	
				if(m=str.match(reg)){
					return {
						type:61,
						time:m[3],
						number:m[1].replace(/^(\d{8})(\d{2})$/, '$1-0$2'),
						data:m[2]
					};
				}					
			}catch(err){
				throw('重庆幸运农场解析数据不正确');
			}
		}
	},
////////////-----------------------PC蛋蛋
	/* {
		title:'PC蛋蛋',
		source:'百度乐彩',
		name:'pcdd',
		enable:true,
		timer:'pcdd',

		option:{
			host:"baidu.lecai.com",
			timeout:30000,
			path: '/lottery/draw/view/543?phase=503062&agentId=5563',
			headers:{
				"User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)"
			}
		},
		
		parse:function(str){
			try{
				return getFrompcdd(str,66);			
			}catch(err){
				throw('PC蛋蛋解析数据不正确');
			}
		}
	}, */
	{
		title:'PC蛋蛋',
		source:'彩票控',
		name:'pcdd',
		enable:true,
		timer:'pcdd2',
		option:{
			host:"api.kaijiangtong.com",
			timeout:30000,
			path: '/lottery/?name=bjklb&format=json&uid=686738&token=78158eceb63e1f7fd4996afd6fea37045d145a84',
			headers:{
				"User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)"
			}
		},
		parse:function(str){
			try{
				var js1 = JSON.parse(str);
				var k;
				for(var p in js1){
				 k = p;
				}
				var datas = js1[k];	
				//data=data.split(',').sort();
				sortNumber = datas['number'].substring(0,59);
				data=sortNumber.split(',');
				var kj1=0,kj2=0,kj3=0;
				for(var i=0 in data){
					if(i<6){
						kj1+=parseInt(data[i],10);
					}else if(i>=6 && i<12){
						kj2+=parseInt(data[i],10);
					}else if(i>=12 && i<=17){
						kj3+=parseInt(data[i],10);
					}	
				}
				if(kj1>=10){kj1=kj1.toString().substr(-1);}
				if(kj2>=10){kj2=kj2.toString().substr(-1);}
				if(kj3>=10){kj3=kj3.toString().substr(-1);}
				if(kj1<0 || kj3<0) throw new Error('PC蛋蛋开奖数据不正确');
				data=kj1+','+kj2+','+kj3;
				var data={
					type:66,
					time:datas['dateline'],
					number:k,
					data:data
				};
				return data;
			}catch(err){
				throw('PC22222蛋蛋解析数据不正确');
			}
		}
	},	
////////////极速时时彩
   {
        title:'极速时时彩',
        source:'BOT',
        name:'jsssc',
        enable:true,
        timer:'jsssc',

        option:{

            host:"b.b1122.cc",
			
            path: '/index.php/Lfc/getXml',
            timeout:5000,
            headers:{
                "User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)"
            }
        },

        parse:function(str){
            try{                                                                                              	//
                str=str.substr(0,200);	                                                                      	//
                var reg=/<row expect="([\d\-]+?)" opencode="([\d\,]+?)" opentime="([\d\:\- ]+?)"/;                   	//
                var m;
                if(m=str.match(reg)){                                                                         	//
                    return {                                                                                  	//
                        type:73,                                                                              	//
                        time:m[3],                                                                            	//
                        number:m[1],                                                                          	//
                        data:m[2]                                                                             	//
                    };                                                                                        	//
                }					                                                                          	//
            }catch(err){                                                                                      	//
                throw('极速时时彩 解析数据不正确');                                                            	//
            }
        }
    },
////////////
    {
		title:'幸运飞艇',
		source:'开彩网',
		name:'mlaft',
		enable:true,
		timer:'mlaft',

		option:{

			host:"luckyairship.com",
			timeout:30000,
			path: '/api/getwiningnumbers.ashx',
			headers:{
				"User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)"
			}
		},
		
		parse:function(str){
			try{

					var myDate = new Date();
	var year = myDate.getFullYear();       //年   
    var month = myDate.getMonth() + 1;     //月   
    var day = myDate.getDate();            //日
	if(month < 10) month="0"+month;
	if(day < 10) day="0"+day;
	var mytime=year + "-" + month + "-" + day + " " +myDate.toLocaleTimeString();
				var m;	 
				var reg=/"openedPeriodNumber":(\d+?),"openedDate"[\s\S]*?"numbersArray":\["([\S]+)"],"curDate"/;
				if(m=str.match(reg)){
					return {
						type:55,
						time:mytime,
						number:m[1],
						data:m[2].replace(/"/g,'')
					};
				}
			}catch(err){
				throw('168kai解析数据不正确');
			}
		}
	},
	
////////////
    {
		title:'江苏快3',
		source:'360彩票',
		name:'jsk3',
		enable:true,
		timer:'jsk3',

		option:{
			host:"cp.360.cn",
			timeout:30000,
			path: '/k3js/',
			headers:{
				"User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)"
			}
		},
		parse:function(str){
			try{
				return getFrom360CPK3(str,10);
			}catch(err){
				throw('江苏快3解析数据不正确');
			}
		}
	},
////////////
    {
		title:'广东11选5',
		source:'360彩票网',
		name:'gd11x5',
		enable:true,
		timer:'gd11x5',

		option:{
			host:"cp.360.cn",
			timeout:50000,
			path: '/gd11/',
			headers:{
				"User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)"
			}
		},
		parse:function(str){
			try{
				return getFrom360CPgd11x5(str,21);
			}catch(err){
				throw('广东11选5解析数据不正确');
			}
		}
	},
////////////
   {                                                                                                                                             
		title: '六合彩',                                                                                                                      
		source: '9800开奖网',                                                                                                                 
		name: 'hklhc',                                                                                                                        
		enable: true,                                                                                                                         
		timer: 'hklhc',                                                                                                                       
		stype: 34,                                                                                                                            
		option: {                                                                                                                             
			host: "www.9800.com.tw",                                                                                                          
			timeout: 50000,                                                                                                                   
			path: '/html/a6/',                                                                                                                
			hhost: "www.9800.com.tw",                                                                                                         
			npath: '/html/a6/',                                                                                                               
			headers: {                                                                                                                        
				"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/22.0.1271.64 Safari/537.11"      
			}                                                                                                                                 
		},                                                                                                                                    
		parse: function(str) {                                                                                                                
			try {                                                                                                                             
				return getFrom9800(str, 70);                                                                                                  
			} catch (err) {}                                                                                                                  
		},                                                                                                                                    
		reparse: function(bet) {                                                                                                              
			try {                                                                                                                             
				log(bet.actionNo);                                                                                                            
				return reparseFrom9800(bet, 70);                                                                                              
			} catch (err) {                                                                                                                   
                                                                                                                                              
			}                                                                                                                                 
                                                                                                                                              
		}                                                                                                                                    
	},                                                                                                                                         

////////////广东快乐十分
   {
		title:'广东快乐十分',
		source:'彩乐乐网',
		name:'klsf',
		enable:true,
		timer:'klsf',

		option:{
			host:"www.cailele.com",
			timeout:50000,
			path: '/static/klsf/newlyopenlist.xml',
			headers:{
				"User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0)"
			}
		},		
		parse:function(str){
			try{
				//return getFromCaileWeb(str,21);
				str=str.substr(0,200);
				var reg=/<row expect="(\d+?)" opencode="([\d\,]+?)" opentime="([\d\:\- ]+?)"/; 
				//<row expect="2013072213" opencode="07,16,03,17,01,05,13,12" opentime="2013-07-22 02:03:20" />
				var m;
	
				if(m=str.match(reg)){
					return {
						type:60,
						time:m[3],
						number:m[1].replace(/^(\d{8})(\d{2})$/, '$1-0$2'),
						data:m[2]
					};
				}					
			}catch(err){
				throw('广东快乐十分解析数据不正确');
			}
		}
	},
////////////
    {                                                                                                           
		title:'北京快乐8',                                                                           				
		source:'北京福利彩票',                                                                                  
		name:'bjk8',                                                                                           
		enable:true,                                                                                            
		timer:'bjk8',                                                                                          
		option:{                                                                                                
			host:"127.0.0.1",                                                                                   
			timeout:50000,                                                                                      
			path: '/xml/kl8/kl8.php',                                                                      			
			headers:{                                                                                           
				"User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "                             
			}                                                                                                   
		},                                                                                                      
		parse:function(str){                                                                                    
			try{                                                                                                
				str=str.substr(0,200);	                                                                        
				var reg=/<row expect="([\d\-]+?)" opencode="([\d\,]+?)" opentime="([\d\:\- ]+?)"/;              
				var m;                                                                                          
				if(m=str.match(reg)){                                                                           
					return {                                                                                    
						type:65,                                                                                
						time:m[3],                                                                              
						number:m[1],                                                                            
						data:m[2]                                                                               
					};                                                                                          
				}					                                                                            
			}catch(err){                                                                                        
				throw('--------官网北京快乐8解析数据不正确');                                                	    
			}                                                                                                   
		}                                                                                                       
	},	
      /**极速 5 六合彩*/
    {
        title:'极速六合彩',
        source:'BOT',
        name:'jslhc',
        enable:true,
        timer:'jslhc',

        option:{

            host:"127.0.0.1",
            timeout:50000,
            path: '/sylot/js_lhc',
            headers:{
                "User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)"
            }
        },

        parse:function(str){
            try{                                                                                              	//
                str=str.substr(0,200);	                                                                      	//
                var reg=/<row expect="([\d\-]+?)" opencode="([\d\,]+?)" opentime="([\d\:\- ]+?)"/;                    	//
                var m;                                                                                        	//
                if(m=str.match(reg)){                                                                         	//
                    return {                                                                                  	//
                        type:74,                                                                              	//
                        time:m[3],                                                                            	//
                        number:m[1],                                                                          	//
                        data:m[2]                                                                             	//
                    };                                                                                        	//
                }					                                                                          	//
            }catch(err){                                                                                      	//
                throw('极速时时彩 解析数据不正确');                                                            	//
            }
        }
    },    
 
];

// 出错时等待 10
exports.errorSleepTime=10;

// 重启时间间隔，以小时为单位，0为不重启
//exports.restartTime=0.4;
exports.restartTime=0;

exports.submit={

	host:'127.0.0.3',
	path:'/admin778899.php/data/kj'
}

exports.dbinfo={
	host:'127.0.0.1',
	port:'3306',
	user:'root',
	password:'root',
	database:'hjcp'

}

global.log=function(log){
	var date=new Date();
	console.log('['+date.toLocaleDateString() +' '+ date.toLocaleTimeString()+'] '+log)
}

function getFromPK10(str, type){

	str=str.substr(str.indexOf('<div class="lott_cont">'),350).replace(/[\r\n]+/g,'');
    //console.log(str);
	var reg=/<tr class=".*?">[\s\S]*?<td>(\d+)<\/td>[\s\S]*?<td>(.*)<\/td>[\s\S]*?<td>([\d\:\- ]+?)<\/td>[\s\S]*?<\/tr>/,
	match=str.match(reg);
	if(!match) throw new Error('数据不正确');
	//console.log(match);
	try{
		var data={
			type:type,
			time:match[3],
			number:match[1],
			data:match[2]
		};
		//console.log(data);
		return data;
	}catch(err){
		throw('解析数据失败');
	}	
}	


function getFrom360CP(str, type){

	str=str.substr(str.indexOf('<em class="red" id="open_issue">'),380);
	//console.log(str);
	var reg=/[\s\S]*?(\d+)<\/em>[\s\S].*?<ul id="open_code_list">((?:[\s\S]*?<li class=".*?">\d+<\/li>){3,5})[\s\S]*?<\/ul>/,
	match=str.match(reg);
	var myDate = new Date();
	var year = myDate.getFullYear();       //年   
    var month = myDate.getMonth() + 1;     //月   
    var day = myDate.getDate();            //日
	if(month < 10) month="0"+month;
	if(day < 10) day="0"+day;
	var mytime=year + "-" + month + "-" + day + " " +myDate.toLocaleTimeString();
	//console.log(match);
	if(match.length>1){
		if(match[1].length==7) match[1]=year+match[1].replace(/(\d{8})(\d{3})/,'$1-$2');
		if(match[1].length==6) match[1]=year+match[1].replace(/(\d{4})(\d{2})/,'$1-0$2');
		if(match[1].length==9) match[1]='20'+match[1].replace(/(\d{6})(\d{2})/,'$1-$2');
		if(match[1].length==10) match[1]=match[1].replace(/(\d{8})(\d{2})/,'$1-0$2');
		var mynumber=match[1].replace(/(\d{8})(\d{3})/,'$1-$2');
		
		try{
			var data={
				type:type,
				time:mytime,
				number:mynumber
			}
			
			reg=/<li class=".*?">(\d+)<\/li>/g;
			data.data=match[2].match(reg).map(function(v){
				var reg=/<li class=".*?">(\d+)<\/li>/;
				return v.match(reg)[1];
			}).join(',');
			
			//console.log(data);
			return data;
		}catch(err){
			throw('解析数据失败');
		}
	}
}

function getFrompcdd(str, type){
	var exp_data = /var latest_draw_result = {"red":\[([0-9\[\]\,\s"]+)\]/;
	var exp_phase = /var latest_draw_phase = '(\d+)';/;
	var exp_time = /var latest_draw_time = '([0-9\-\:\s]+)';/;
	var m_data = str.match(exp_data);
	var m_phase = str.match(exp_phase);
	var m_time = str.match(exp_time);
	if(m_data && m_phase && m_time){
		var mytime=m_time[1];
		var mynumber=m_phase[1];
		var data=m_data[1].replace(/"/g, '');
	}		
	if(!mytime || !mynumber || !data) throw new Error('PC蛋蛋数据不正确');
	data=data.split(',').sort();
	var kj1=0,kj2=0,kj3=0;
	for(var i=0 in data){
		if(i<6){
			kj1+=parseInt(data[i],10);
		}else if(i>=6 && i<12){
			kj2+=parseInt(data[i],10);
		}else if(i>=12 && i<=17){
			kj3+=parseInt(data[i],10);
		}	
	}
	if(kj1>=10){kj1=kj1.toString().substr(-1);}
	if(kj2>=10){kj2=kj2.toString().substr(-1);}
	if(kj3>=10){kj3=kj3.toString().substr(-1);}
	if(kj1<0 || kj3<0) throw new Error('PC蛋蛋开奖数据不正确');
	data=kj1+','+kj2+','+kj3;
	try{
		
		var data={
			type:type,
			time:mytime,
			number:mynumber,
			data:data
		};
		//console.log(data);
		return data;
	}catch(err){
		throw('===========================================================解析PC蛋蛋数据失败');
	}
	
}

function getFrom360CPK3(str, type){

	str=str.substr(str.indexOf('<em class="red" id="open_issue">'),380);
	//console.log(str);
	var reg=/[\s\S]*?(\d+)<\/em>[\s\S].*?<ul id="open_code_list">((?:[\s\S]*?<li class=".*?">\d+<\/li>){3,5})[\s\S]*?<\/ul>/,
	match=str.match(reg);
	var myDate = new Date();
	var year = myDate.getFullYear();       //年   
    var month = myDate.getMonth() + 1;     //月   
    var day = myDate.getDate();            //日
	if(month < 10) month="0"+month;
	if(day < 10) day="0"+day;
	var mytime=year + "-" + month + "-" + day + " " +myDate.toLocaleTimeString();
	match[1]=match[1].replace(/(\d{4})(\d{2})/,'$1'+0+'$2');
	//console.log(match[1]);
	var mynumber=year.toString().substr(-2)+match[1];	
		try{
			var data={
				type:type,
				time:mytime,
				number:mynumber
			}
			
			reg=/<li class=".*?">(\d+)<\/li>/g;
			data.data=match[2].match(reg).map(function(v){
				var reg=/<li class=".*?">(\d+)<\/li>/;
				return v.match(reg)[1];
			}).join(',');
			
			//console.log(data);
			return data;
		}catch(err){
			throw('解析数据失败');
		}
}

function getFrom360CPgd11x5(str, type){

	str=str.substr(str.indexOf('<em class="red" id="open_issue">'),380);
	//console.log(str);
	var reg=/[\s\S]*?(\d+)<\/em>[\s\S].*?<ul id="open_code_list">((?:[\s\S]*?<li class=".*?">\d+<\/li>){3,5})[\s\S]*?<\/ul>/,
	match=str.match(reg);
	var myDate = new Date();
	var year = myDate.getFullYear();       //年   
    var month = myDate.getMonth() + 1;     //月   
    var day = myDate.getDate();            //日
	if(month < 10) month="0"+month;
	if(day < 10) day="0"+day;
	var mytime=year + "-" + month + "-" + day + " " +myDate.toLocaleTimeString();
	if(match.length>1){
		var mynumber=year.toString().substr(-2)+match[1].replace('-','');
		
		try{
			var data={
				type:type,
				time:mytime,
				number:mynumber
			}
			
			reg=/<li class=".*?">(\d+)<\/li>/g;
			data.data=match[2].match(reg).map(function(v){
				var reg=/<li class=".*?">(\d+)<\/li>/;
				return v.match(reg)[1];
			}).join(',');
			
			//console.log(data);
			return data;
		}catch(err){
			throw('解析数据失败');
		}
	}
}

function reparseFrom9800(bet, type) {
	str = bet.str;

	exports.errorSleepTime=500;  

	reg = new RegExp("<TD bgColor=#f6f6f6 align=\"center\"" + bet.actionNo + "<\/TD>[\s\S].*?<TD align=middle>(.*?)<\/TD>[\s\S].*?<TD align=middle>[\s\S].*?<font color=\"#FF0000\"><b>(\d+) (\d+) (\d+) (\d+) (\d+) (\d+)<\/b><\/font>[\s\S].*?\+ <b><font color=\"#009933\">(\d+)<\/font><\/b>", ""); //

	match = str.match(reg);
	var myDate = new Date();
	var year = myDate.getFullYear(); //年
	var month = myDate.getMonth() + 1; //月
	var day = myDate.getDate(); //日
	if (month < 10) month = "0" + month;
	if (day < 10) day = "0" + day;
	var mytime = match[1] + " " + myDate.toLocaleTimeString();
	try {
		var data = {
			type: type,
			time: mytime,
			number: bet.actionNo
		}

		data.data = match[2] + "," + match[3] + "," + match[4] + "," + match[5] + "," + match[6] + "," + match[7] + "," + match[7];

		//console.log(data);
		return data;
	} catch (err) {
		throw ('解析数据失败');
	}

}

function getFrom9800(str, type) {

	str = str.substr(str.indexOf('bai12'), 560);
	exports.errorSleepTime=500;  

	var reg = /<TD bgColor=#f6f6f6 align="center">(\d+)<\/TD>[\s\S].*?<TD align=middle>(.*?)<\/TD>[\s\S].*?<TD align=middle>[\s\S].*?<font color="#FF0000"><b>(\d+) (\d+) (\d+) (\d+) (\d+) (\d+)<\/b><\/font>[\s\S].*?\+ <b><font color="#009933">(\d+)<\/font><\/b>/,
		match = str.match(reg);

	var myDate = new Date();
	var year = myDate.getFullYear(); //年
	var month = myDate.getMonth() + 1; //月
	var day = myDate.getDate(); //日
	if (month < 10) month = "0" + month;
	if (day < 10) day = "0" + day;
	var mytime = match[2] + " " + myDate.toLocaleTimeString();
	try {
		var data = {
			type: type,
			time: mytime,
			number: match[1]
		}

		data.data = match[3] + "," + match[4] + "," + match[5] + "," + match[6] + "," + match[7] + "," + match[8] + "," + match[9];

		//console.log(data);
		return data;
	} catch (err) {
		throw ('解析数据失败');
	}

}